/*
 * This class is part of the "gwt-tinymce" library.  
 * Copyright (C)2008 Collegeman.net, LLC.  
 * Adjustments for the Netzpult project Copyright (c) 2011 Ulrich Hilger, uhilger.de
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package de.uhilger.netzpult.client;

import com.google.gwt.user.client.Random;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * EditorFactory for TinyMCE 
 * 
 * @author by Aaron Collegeman, http://collegeman.net 
 * @author adjustments for the Netzpult project by Ulrich Hilger, http://uhilger.de
 * @author Published under the terms and conditions of
 * the <a href="http://www.gnu.org/licenses/" target="_blank">GNU General Public License</a>
 */
public class EditorFactory {

	public static Editor getEditor(int height) {
		EditorImpl editor = new EditorImpl();
		editor.init(Integer.toString(height - 50) + "px");
		return editor;
	}

	private static class EditorImpl extends Editor {

		public EditorImpl() {
			this.id = Random.nextInt(2147483647) + "mce";

			TextArea ta = new TextArea();
			ta.removeStyleName("gwt-TextArea");
			ta.addStyleName(id);
			ta.getElement().setAttribute("id", id);

			Panel panel = new VerticalPanel();
			panel.setSize("100%", "100%");
			panel.add(ta);

			initWidget(ta);
		}

		/*
		  valid_elements: "*[*]",
		 */
		private native void init(String taHeight) /*-{
			$wnd.tinyMCE.init({
	        mode: "textareas",

	        theme: "advanced",
	        skin: "o2k7",
	        skin_variant: "silver",
	        
	        content_css: "../tinymce_content.css",

        	plugins : "spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

	        theme_advanced_buttons1 : "cut,copy,paste,pastetext,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect,|,charmap,fullscreen,|,hr,removeformat,visualaid,|,sub,sup",
	        theme_advanced_buttons2 : "search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,preview,code,|,forecolor,backcolor,|,tablecontrols,|,styleprops,spellchecker,|,visualchars",
	        theme_advanced_buttons3 : "",
	        theme_advanced_buttons4 : "",
	        
					theme_advanced_fonts : "Andale Mono=andale mono,times;"+
							"Arial=arial,helvetica,sans-serif;"+
							"Arial Black=arial black,avant garde;"+
							"Book Antiqua=book antiqua,palatino;"+
							"Comic Sans MS=comic sans ms,sans-serif;"+
							"Courier New=monospace,courier new,courier;"+
							"Georgia=georgia,palatino;"+
							"Helvetica=helvetica;"+
							"Impact=impact,chicago;"+
							"Symbol=symbol;"+
							"Tahoma=tahoma,arial,helvetica,sans-serif;"+
							"Terminal=terminal,monaco;"+
							"Times New Roman=times new roman,times;"+
							"Trebuchet MS=trebuchet ms,geneva;"+
							"Verdana=verdana,geneva;"+
							"Webdings=webdings;"+
							"Wingdings=wingdings,zapf dingbats",	        
	       	        
					theme_advanced_resize_horizontal : true,
					theme_advanced_resizing : true,
					auto_resize : true,

	        theme_advanced_toolbar_location: "top",
	        theme_advanced_toolbar_align: "left",

	        width: "100%",
	        height: taHeight,

	        editor_selector: this.@de.uhilger.netzpult.client.Editor::id
			});
		}-*/;

	}

}
